<template>
    <base-breadcrumb>
        <template>
            <div class="table-page-search-wrapper">
                <searchData :searchData="searchArr" @search="search"></searchData>
            </div>
        </template>
        <a-card>
            <list-table
                ref="table"
                size="default"
                rowKey="key"
                :columns="columns"
                :request="loadData"
                :alert="true"
                show-size-changer
                show-quick-jumper
                showPagination="auto"
                :export-config="{
                        use: true,
                        select: '总包施工图预算',
                        all: '总包施工图预算'
                    }"
                :exportPermission="{ select: 'bm_007_exp_03', all: 'bm_007_exp_03' }"
                     :statistics-config="{ use: true,  countList, temp }"
            >
                <span slot="operation" slot-scope="text, record">
                    <MoreButton>
                     <a @click="detailed(record)" v-btnPermission="'bm_007_loo_02'">查看</a>
                    <span
                        v-if="(record.auditStatus=='DRAFT')&& hideBuquBtn()"
                            v-btnPermission="'bm_007_edi_01'"
                    >
                        <a @click="addEdit(record)">编辑</a>
                    </span>
                    <!-- v-if="record.auditStatus=='DRAFT'" -->
                        </MoreButton>
                </span>
            </list-table>
        </a-card>
    </base-breadcrumb>
</template>

<script>
import { getList, getListCount, addList, editList, deteleList, cancelList } from '@/api/businessAffairs/lumpSumBudget'
import OrgTreeSelect from '@/components/OrgTreeSelect'
import { STable } from '@/components'
import BasePage from '@/views/basePage' // 基础配置
const columns = [
    {
        title: '名称',
        dataIndex: 'name'
    },
    {
        title: '所属分公司',
        dataIndex: 'branchComName'
    },
    {
        title: '所属项目',
        dataIndex: 'projectName'
    },
    {
        title: '自行完成施工图预算价款(万元)',
        dataIndex: 'budgetPrice'
    },
    {
        title: '业主指定分包价款(万元)',
        dataIndex: 'subcontractPrice'
    },
    {
        title: '施工图预算总额(万元)',
        dataIndex: 'totalBudget'
    },
    {
        title: '填报人',
        dataIndex: 'creatorName'
    },
    {
        title: '填报时间',
        dataIndex: 'createTime'
    },
    {
        title: '状态',
        dataIndex: 'auditStatusName',
    //     dataIndex: 'auditStatus',
    //     customRender: (text) => {
    //      if(text == 'DRAFT'){
    //         return  '待提交'
    //     }else{
    //         return  '已提交'
    //     }
    //   }
    },
    {
        title: '操作',
        dataIndex: 'operation',
        width: '170px',
        scopedSlots: { customRender: 'operation' }
    }
]
const searchArr = [
  {
    name: '所属单位',
    valueKey: 'searchQuery',
    type: OrgTreeSelect,
  },
    {
        name: '填报人',
        value: 'creatorName',
        type: 'input'
    },
    {
        name: '填报时间',
        value: 'startEndDate',
        type: 'dateRange'
    },
    {
        name: '状态',
        value: 'auditStatus',
        type: 'select',
        data: typeListApproval3
    }
]
import { typeListApproval3 } from '@/utils/util'
export default {
    name: 'a' + Date.now(),
    extends: new BasePage(),
    components: {
        STable
    },
    data() {
        this.columns = columns
        this.searchArr = searchArr
        return {
            from: {},
            countList:{},
            queryParam: {},
            userId: JSON.parse(sessionStorage.getItem('ycloud-user_info')).id,
            loadData: (parameter) => {
                const requestParameters = Object.assign({}, parameter, this.queryParam)
                if (this.queryParam.startEndDate) {
                    requestParameters.createTimeBegin =
                        this.queryParam.startEndDate[0].format('YYYY-MM-DD HH:mm:ss') || void 0
                    requestParameters.createTimeEnd =
                        this.queryParam.startEndDate[1].format('YYYY-MM-DD HH:mm:ss') || void 0
                }
                this.getListCount(requestParameters)
                return getList(requestParameters).then((res) => {
                    console.log('数据返回对象：', res)
                    res.data.forEach(item => {
                        if(item.auditStatus == 'DRAFT'){
                            item.auditStatusName='待提交'
                        }else{
                            item.auditStatusName='已提交'
                        }
                    });
                    return res
                })
            },
            temp: () => {
            return (
                <span style="margin-right: 12px">
                 自行完成施工图预算价款(万元)：<span class="totalNum">{ this.countList.budgetPrice }  </span> 
                 业主指定分包价款(万元)：<span class="totalNum">{this.countList.subcontractPrice}  </span> 
                 施工图预算总额(万元)：<span class="totalNum">{this.countList.totalBudget}  </span> 
                </span>
            )
          },
            removeApi: { invalid: cancelList, undo: cancelList } // api
        }
    },
    methods: {
        //搜索
        search(value) {
            this.queryParam = value
            this.$refs.table.refresh(true)
        },
        getListCount(requestParameters) {
            getListCount(requestParameters).then((res) => {
                this.countList = res.data
            })
        },

        handleUpdate() {},
        //新增
        // handleAdd() {
        //     this.$router.push('/businessAffairs/constructionBudget/lumpSumBudget/newIncrease')
        // },
        // 查看
        detailed(e) {
            this.$router.push({
                path: '/businessAffairs/constructionBudget/lumpSumBudget/newIncrease',
                query: { id: e.id, type: 'view' }
            })
        },
        //编辑
        addEdit(e) {
            this.$router.push({
                path: '/businessAffairs/constructionBudget/lumpSumBudget/newIncrease',
                query: { id: e.id, type: 'edit' }
            })
        }
    }
}
</script>

<style lang="less">
.not-submit {
    display: inline-block;
    padding: 0;
    li {
        list-style: disc;
        color: red;
    }
}
.submitted {
    display: inline-block;
    padding: 0;
    li {
        list-style: disc;
        color: green;
    }
}
</style>
